<meta title="用户权限管理"/>
<div class="p">
    <div class="m-b clearfix">
        <form class="form-inline pull-left" id="form" s="form,valid">
            <input autocomplete="off" type="text" class="form-control input-sm" s-valid-error="require()" placeholder="输入手机号查找用户" style="width:200px;" name="phone" />
            <button type="button" class="btn btn-default btn-sm" s-click="$form.validate().done(function() {$userPanel.refresh()})">查询</button>
        </form>
    </div>
    <div id="userPanel"
         s='datac,nda,check'
         s-data-switch="'off-on'"
         s-data="S.get('/api/user/authorize-by-phone', $form.node.serialize())">
        <table class="table table-striped table-bordered table-middle">
            <tr>
                <td style="width: 200px;">手机号：<input autocomplete="off" type="hidden" name="user.id" id="userId" /> </td>
                <td name="user.phone"></td>
                <td style="width: 200px;">昵称：</td>
                <td name="user.nickname"></td>
            </tr>
        </table>
        <table class="table table-striped table-bordered table-hover table-middle">
            <tr>
                <th>权限</th>
                <th class="text-right">操作</th>
            </tr>
            <tbody s="loop" s-data-filter="'authorizeList'">
            <tr s-loop-role="empty">
                <td colspan="2">暂无数据</td>
            </tr>
            <tr s-loop-role="row" s-check-role="i" s="datac" class="commissionItem">
                <td name="authorizeTitle"></td>
                <td class="text-right">
                    <input autocomplete="off" type="button" class="btn btn-danger btn-outline btn-sm" s-click="del(this)" value="删除"/>
                </td>
            </tr>
            </tbody>
            <tfoot>
            <tr class="form-inline">
                <td colspan="2">
                    <select class="form-control input-sm" s="select" id="authorize" s-build="S.get('/api/enum/valuesMap/core.enums.Authorize')"
                            name="status">
                    </select>
                    <input autocomplete="off" type="button" class="btn btn-primary btn-sm btn-outline" s-click="add()" value="新增"/>
                </td>
            </tr>
            </tfoot>
        </table>
    </div>
</div>
<script type="text/javascript">

    function add() {
        S.post("/api/user-authorize", {userId: $userId.node.val(), authorize: $authorize.node.val()}).done(function() {
            $userPanel.refresh()
        })
    }
``
    function del($this) {
        var data = $this.parent().data();
        S.remove("/api/user-authorize/" + $userId.node.val() + '-' + data.authorize).done(function() {
            $userPanel.refresh()
        })
    }

</script>